﻿using ASmile.Win.Controls;
using System;
using System.Windows.Forms;

namespace ASmile.Win.Forms
{
    public partial class FrmSelectTree : FrmBaseModal
    {
        public FrmSelectTree()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 初始化treeview的方法
        /// </summary>
        public Action<TreeViewEx> InitTreeHandle;
        /// <summary>
        /// 选中后触发
        /// </summary>
        public Func<TreeViewEx, ApiResult> OnSelected;

        private void FrmSelectTree_Load(object sender, EventArgs e)
        {
            InitTreeHandle(tv);
        }

        private void tsBtnSelected_Click(object sender, EventArgs e)
        {   
            var r = OnSelected(tv);
            if (!r)
            {
                ShowMessage(r.msg);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        private void tsBtnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tv_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (!tv.CheckBoxes) tsBtnSelected_Click(sender, e);
        }
    }
}